#! /bin/bash
export LANG=zh_CN.UTF-8
PRESTO_HOME=/export/server/presto/bin/presto


${PRESTO_HOME} --catalog hive --server 192.168.88.80:8090 --execute "

--动态分区配置
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=10000;
set hive.exec.max.dynamic.partitions=100000;
set hive.exec.max.created.files=150000;
--hive压缩
set hive.exec.compress.intermediate=true;
set hive.exec.compress.output=true;
--写入时压缩生效
set hive.exec.orc.compression.strategy=COMPRESSION;

-- 考勤宽表
INSERT INTO TABLE edu_dws.t_signin_detail PARTITION (dt)
SELECT
           ctup.id,
           normal_class_flag,
           time_table_id,
           ctup.class_id,
           student_id,
           substring(signin_time,12,8) AS signin_time,
           signin_date,
           share_state,
           morning_template_id,
           morning_begin_time,
           morning_end_time,
           afternoon_template_id,
           afternoon_begin_time,
           afternoon_end_time,
           evening_template_id,
           evening_begin_time,
           evening_end_time,
           use_begin_date,
           use_end_date,
           base_id,
           class_date,
           content,
           teacher_id,
           teacher_name,
           job_number,
           classroom_id,
           classroom_name,
           ctup.dt
FROM edu_dwd.dwd_ft_tbh_student_signin_record  ctup
JOIN edu_dwd.dwd_dt_tbh_class_time_table dtctt
on ctup.time_table_id = dtctt.id
JOIN edu_dwd.dwd_dt_course_table_upload_detail dctud
ON ctup.class_id = dctud.class_id AND ctup.signin_date = dctud.class_date;


-- 请假宽表
INSERT OVERWRITE TABLE edu_dws.t_leave_detail PARTITION (dt)
SELECT
       dfsla.class_id,
       student_id,
       leave_type,
       leave_reason,
       begin_time,
       begin_time_type,
       end_time,
       end_time_type,
       days,
       cancel_state,
       cancel_time,
       leave_remark,
       old_leave_id,
       valid_state,
       school_id,
       subject_id,
       studying_student_count,
       studying_date,
       morning_template_id,
       morning_begin_time,
       morning_end_time,
       afternoon_template_id,
       afternoon_begin_time,
       afternoon_end_time,
       evening_template_id,
       evening_begin_time,
       evening_end_time,
       use_begin_date,
       use_end_date,
       ddtctt.dt
FROM edu_dwd.dwd_ft_student_leave_apply  dfsla
JOIN edu_dwd.dwd_dt_class_studying_student_count ddcssc
ON dfsla.class_id = dfsla.class_id
JOIN edu_dwd.dwd_dt_tbh_class_time_table ddtctt
ON dfsla.class_id = ddtctt.class_id;
"